package com.example.firstapp.KtLesson

fun main() {

    //infix fun 接收者类型.函数名(参数: 参数类型): 返回类型

    infix fun String.beginsWith(prefix: String) = startsWith(prefix)
    if ("hello world" beginsWith "hello"){
        println("hello")
    }

    val list = listOf("Apple", "Banana", "Orange", "Pear", "Grape")
    if (list.contains("Banana")) {
        println("no infix")
    }

    // 第一个<T> 声明是泛型函数
    infix fun <T> Collection<T>.has(element: T) = contains(element)
    if( list has "banana"){
        println("banana")
    }
 // infix fun <A, B> A.with(that: B): Pair<A, B> = Pair(this, that)
    //Pair<A, B>返回值类型 可写可不写
    infix fun <A, B> A.with(that: B)= Pair(this, that)
    val map = mapOf(
        "Apple" with 1,
        "Banana" with 2,
        "Orange" with 3,
        "Pear" with 4,
        "Grape" with 5)
    println(map["Apple"])

}